package lab4Source;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Vector;

public class S_CountVisitor extends AbstractVisitor {
	private int counter;
	
	public S_CountVisitor() {
		super();
		this.counter = 0;
	}
	
	public int S_getCount() {
		return this.counter;
	}
	
	@Override
	public void visit(Square s) {
		this.counter++;
		if (s.hasChildren()) {
			Vector<AbstractShape> children = s.S_getChildren();
			Iterator iterator = children.iterator();
			while (iterator.hasNext()) {
				AbstractShape shape = (AbstractShape)iterator.next();
				if (shape.getClass() == Square.class) {					
					this.visit((Square)shape);
				} else if (shape.getClass() == Rectangle.class) {
					this.visit((Rectangle)shape);
				} else if (shape.getClass() == Circle.class) {
					this.visit((Circle)shape);
				} else if (shape.getClass() == Triangle.class) {
					this.visit((Triangle)shape);
				} else if (shape.getClass() == SquareProxy.class || shape.getClass() == Square.class) {
					this.visit((SquareProxy)shape);
				} else {
					System.out.println("Debug info: unknown class for some reasons");
					System.out.println(shape.getClass().toString());
				}				
			}
		}		
	}

	@Override
	public void visit(Rectangle r) {
		this.counter++;
	}

	@Override
	public void visit(Circle c) {		
		this.counter++;
	}

	@Override
	public void visit(Triangle t) {
		this.counter++;
	}

	@Override
	public void visit(SquareProxy sp) {
		this.counter++;
	}
}
